package com.kingwood.algorithm.zuochengyun.digui;

/**
 * @Author 22025812
 * @Description: TODO
 * @Date: 2024/3/11 18:18
 * @Modified By：
 * @Version 1.0
 */
public class IsSumOfConsecutiveNumbers {

    public static boolean isSumOfConsecutiveNumbers(int num) {
        for (int start = 1, sum; start <= num; start++) {
            sum = start;
            for (int j = start + 1; j <= num; j++) {
                if (sum + j > num) {
                    break;
                }
                if (sum + j == num) {
                    return true;
                }
                sum += j;
            }
        }

        return false;
    }

    public static boolean is2(int num) {
        return (num & (num - 1)) != 0;
    }

    public static void main(String[] args) {
        for (int num = 1; num < 200; num++) {
            System.out.println(num + " : " + (isSumOfConsecutiveNumbers(num) ? "T" : "F"));
        }
    }
}
